package com.xunyu.shopping_manager_api.security;

import cn.dev33.satoken.stp.StpInterface;
import com.xinyu.shopping_common.entity.Permission;
import com.xinyu.shopping_common.service.IAdminService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class StpInterfaceImpl implements StpInterface {


    @DubboReference
    private IAdminService adminService;

    /**
     * 获取所有的权限
     * @param loginId
     * @param loginType
     * @return
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {

        //将登录id转换成字符串（登录的账号）
        String username = (String)loginId;
        //根据账号获取所有的权限
        List<Permission> allPermission = adminService.findAllPermission(username);

        //获取所有的url 地址作为权限表达式
        List<String> permissions = allPermission.stream().map(Permission::getUrl).toList();
        // ["/admin/search","/goods/search"]

        return permissions;
    }

    /**
     * 获取所有的角色
     * @param o
     * @param s
     * @return
     */
    @Override
    public List<String> getRoleList(Object o, String s) {
        return null;
    }
}
